<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author root
 */
class login extends admintemp {
    
    public function __construct() {
        parent::__construct();
    }
    
    public function index(){
        if($_POST['click']){
            if($_POST['username']&&$_POST['password']){
                $name = $_POST['username'];
                $password = $_POST['password'];
                $mysqldb = new db();
                $userinfo = $mysqldb->fetch_arrone("select * from user where `name`='$name'");
                if($userinfo==NULL){
                    print_r($userinfo);
                    echo "用户不存在";
                }else{
                    if($userinfo['password']==md5($password)){
                        $_SESSION[authname]=md5($name);
                        $_SESSION[authpd]=md5($password);
                        redirect(WEBPATH."?c=mydefault");   
                    }else{
                        echo "密码不正确";
                        $this->display("error.html");
                    }
                }
            }else{
                $this->display("login.html");
            }
        }else{
            if(isset($_SESSION['authpd'])){
                redirect(WEBPATH."?c=mydefault");
            }else{
                $this->display("login.html");
            }
        }
    }
    
    public function logout(){
        unset($_SESSION['authname']);
        unset($_SESSION['authpd']);
        $this->index();
    }
}

?>
